<%--
  Created by IntelliJ IDEA.
  User: 唐清枫
  Date: 2023/9/10
  Time: 16:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录界面</title>

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="application/x-javascript"> addEventListener("load", function () {
        setTimeout(hideURLbar, 0);
    }, false);

    function hideURLbar() {
        window.scrollTo(0, 1);
    } </script>
    <!-- Custom Theme files -->
    <link href="static/css/login.css" rel="stylesheet" type="text/css" media="all"/>
    <script src="static/js/vue.js"></script>
    <script src="static/js/jquery-3.2.1.min.js"></script>
    <script src="static/js/vue.js"></script>
    <script src="static/js/Core_values.js"></script>
    <!-- //Custom Theme files -->

    <style>
        #b{
            width: 250px;
            height: 35px;
            margin-top: 30px;
            margin-left: 90px;
            background-color: mediumblue;
            color: white;
            font-size: 20px;
        }
    </style>
</head>
<body>
<div id="app" style="margin-top: 50px">
    <div class="login-form w3-agile">
        <h2>考勤管理系统</h2>
        <form>
            <p>请输入账号</p>
            <input type="text" name="username" required="" id="userName" placeholder="在这输入您的账号"/>
            <p>请输入密码</p>
            <input type="password" name="password" required="" id="userPwd" placeholder="在这输入您的密码"/>
            <input type="button" value="登录" onclick="login()" id="b">
        </form>
        <a href="./jsp/email.jsp">忘记密码</a>
    </div>
</div>
<!-- //copyright -->

<script>
    function login() {
        var userName=$("#userName").val()
        var userPwd=$("#userPwd").val()
        var user = {
            "userName":userName,
            "userPwd":userPwd
        }
        $.ajax({
            url:"user/login",
            type:"post",
            contentType:"application/json",
            data:JSON.stringify(user),
            success:function (res) {
                if (res.status===200){
                    localStorage.setItem("userName",JSON.stringify(user.userName));  //上传角色信息到本地服务器上
                    window.location.href="index.jsp"
                }else if(res.status===500){
                    alert("密码错误")
                }
            },
            error:function () {
                alert("服务器错误")
            }
        })
    }
</script>
</body>


</html>
